package com.wxdc.nmgyt.nmgytwydc.common;

import android.os.Bundle;
import android.util.Log;

import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.Marker;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.model.LatLng;
import com.wxdc.nmgyt.nmgytwydc.R;
import com.wxdc.nmgyt.nmgytwydc.model.JcdInfoBean;

/**
 * Created by Administrator on 2018/5/29.
 */

public class BaiduMapDrawGraph {
    private final String TAG = this.getClass().getSimpleName();
    private static volatile  BaiduMapDrawGraph instance;
    private BaiduMapDrawGraph(){

    }
    public static BaiduMapDrawGraph getInstance(){
        if (instance == null) {
            synchronized (BaiduMapDrawGraph.class) {
                if (instance == null) {
                    instance = new BaiduMapDrawGraph();
                }
            }
        }
        return instance;
    }

    /**
     * 将监测点信息标记在百度地图上
     * @param baiduMap
     * @param obj
     * @return
     */
    public  void drawMarkerToMap(BaiduMap baiduMap,JcdInfoBean obj) {
        Marker marker;
        baiduMap.clear();
        Log.i(TAG, "drawMarkerToMap: ---------" + obj.getJDD() + "--" + obj.getJDF() + "----" + obj.getJDM());
        double jd = obj.getJd();
        double wd = obj.getWd();
        LatLng latLng = null;
        OverlayOptions markerOptions = null;
        BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.yangdi);
        latLng = CoordinateConvert.getInstance().latLngConVert(new LatLng(wd, jd));
        markerOptions = new MarkerOptions()
                .position(latLng).icon(bitmapDescriptor).visible(true).zIndex(10).alpha(0.8f);
        marker = (Marker) baiduMap.addOverlay(markerOptions);
        Bundle bundle = new Bundle();
        bundle.putSerializable("jczInfoObj", obj);
        marker.setExtraInfo(bundle);
        // 将地图移到到最后一个经纬度位置
        //Log.i(TAG, "将地图移到到最后一个经纬度位置: "+latLng.longitude);
        MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(latLng); //.newLatLng(latLng);
        baiduMap.setMapStatus(u);
        //return marker;
    }
}
